﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;

using System.Web;
using System.Web.UI;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using System.Web.Mvc.Html;
using System.Web.Routing;

//using VietPublisher.BSL.SC;
using VietPublisher.FileManager;

namespace VietPublisher.Web.Controls
{
    static public class HtmlHelperExtension
    {
        //static VietPublisherEntities EntityContext = new VietPublisherEntities();

        //static public string ControllerName(this HtmlHelper htmlHelper)
        //{
        //    return htmlHelper.ViewContext.RouteData.Values["controller"].ToString();
        //}

        //static public string ActionName(this HtmlHelper htmlHelper)
        //{
        //    return htmlHelper.ViewContext.RouteData.Values["action"].ToString();
        //}

        ///// <summary>
        ///// Get subsystem name, like EM, WM, SC, SM..
        ///// </summary>
        ///// <param name="htmlHelper"></param>
        ///// <returns></returns>
        //static public string SubSystemName(this HtmlHelper htmlHelper)
        //{
        //    string fullName = htmlHelper.ViewContext.Controller.GetType().FullName;
        //    if (fullName.StartsWith("VietPublisher.Web"))
        //    {
        //        return fullName.Substring("VietPublisher.Web.".Length, 2);
        //    }
        //    else
        //    {
        //        return "SC";
        //    }
        //}

        //public static string RadioButtonList2(this HtmlHelper helper, string name, IEnumerable<SelectListItem> itemList, object routeValue, object itemRouteValue)
        //{
        //    StringBuilder resultBuilder = new StringBuilder();
        //    RouteValueDictionary routeAttributes = new RouteValueDictionary(routeValue);

        //    TagBuilder tagBuilder = new TagBuilder("span");
        //    tagBuilder.MergeAttributes(routeAttributes);

        //    if (itemList != null && itemList.Count() > 0)
        //    {
        //        foreach (SelectListItem item in itemList)
        //        {
        //            resultBuilder.Append("<span>" +
        //                helper.RadioButton(name, item.Value, routeValue != null && item.Value.ToLower() == routeValue.ToString().ToLower(), itemRouteValue)
        //                + string.Format("<label>{1}</label>", name, item.Text)
        //                + "</span>"
        //                );
        //        }
        //    }
        //    tagBuilder.InnerHtml = resultBuilder.ToString();
        //    return tagBuilder.ToString();
        //}


        //public static string RadioButtonList(this HtmlHelper helper, string name, IEnumerable<SelectListItem> itemList, object routeValue, object itemRouteValue)
        //{
        //    StringBuilder resultBuilder = new StringBuilder();
        //    RouteValueDictionary routeAttributes = new RouteValueDictionary(routeValue);

        //    TagBuilder tagBuilder = new TagBuilder("span");
        //    tagBuilder.MergeAttributes(routeAttributes);

        //    if (itemList != null && itemList.Count() > 0)
        //    {
        //        int i = 0;
        //        foreach (SelectListItem item in itemList)
        //        {
        //            resultBuilder.Append("<span>" +
        //                helper.RadioButton(name, item.Value, item.Selected, itemRouteValue).ToHtmlString().Replace("id=\"" + name + "\"", "id=\"" + name + i.ToString() + "\"")
        //                //+ string.Format("<span>{0}</span>", item.Text)
        //                + string.Format("<label style=\"float: none;\" class=\"radio_label\" for=\"{0}\">{1}</label>", name + i.ToString(), item.Text)
        //                + "</span>"
        //                );
        //            i++;
        //        }
        //    }
        //    tagBuilder.InnerHtml = resultBuilder.ToString();
        //    return tagBuilder.ToString();
        //}

        //public static string RadioButtonList(this HtmlHelper helper, string name, IEnumerable<SelectListItem> itemList, object routeValue, object itemRouteValue, object lableRouteValue)
        //{
        //    StringBuilder resultBuilder = new StringBuilder();
        //    RouteValueDictionary routeAttributes = new RouteValueDictionary(routeValue);
        //    RouteValueDictionary labelRouteAttributes = new RouteValueDictionary(lableRouteValue);
        //    labelRouteAttributes.Add("for", "{0}");

        //    TagBuilder tagBuilder = new TagBuilder("span");
        //    tagBuilder.MergeAttributes(routeAttributes);
        //    TagBuilder labelBuilder = new TagBuilder("label");
        //    labelBuilder.MergeAttributes(labelRouteAttributes);
        //    labelBuilder.InnerHtml = "{1}";

        //    if (itemList != null && itemList.Count() > 0)
        //    {
        //        int i = 0;
        //        foreach (SelectListItem item in itemList)
        //        {
        //            resultBuilder.Append(
        //                helper.RadioButton(name, item.Value, item.Selected, itemRouteValue).ToHtmlString().Replace("id=\"" + name + "\"", "id=\"" + name + i.ToString() + "\"")
        //                //+ string.Format("<span>{0}</span>", item.Text)
        //                + string.Format(labelBuilder.ToString(), name + i.ToString(), item.Text)

        //                );
        //            i++;
        //        }
        //    }
        //    tagBuilder.InnerHtml = resultBuilder.ToString();
        //    return resultBuilder.ToString();
        //}

        //public static string RadioButtonListTextAfter(this HtmlHelper helper, string name, IEnumerable<SelectListItem> itemList, object routeValue, object itemRouteValue)
        //{
        //    StringBuilder resultBuilder = new StringBuilder();
        //    RouteValueDictionary routeAttributes = new RouteValueDictionary(routeValue);

        //    TagBuilder tagBuilder = new TagBuilder("span");
        //    tagBuilder.MergeAttributes(routeAttributes);

        //    if (itemList != null && itemList.Count() > 0)
        //    {
        //        foreach (SelectListItem item in itemList)
        //        {
        //            resultBuilder.Append("<span>" +
        //                 helper.RadioButton(name, item.Value, item.Selected, itemRouteValue)
        //                 + string.Format("<span>{0}</span>", item.Text)
        //                + "</span>"
        //                );
        //        }
        //    }
        //    tagBuilder.InnerHtml = resultBuilder.ToString();
        //    return tagBuilder.ToString();
        //}

        //public static string RadioButtonList(this HtmlHelper helper, string name, IEnumerable<SelectListItem> itemList, object itemRouteValue)
        //{
        //    return helper.RadioButtonList(name, itemList, null, itemRouteValue);
        //}

        //public static string ToGroupRadioButtonList(this HtmlHelper helper, string name, string groupCode, string selectedValue, bool includeAll, object routeValue, object itemRouteValue)
        //{
        //    var subCodeItems = EntityContext.vw_T_SC_SubCode
        //        .Where(item => item.GroupCode == groupCode)
        //        //.Where(item => item.GroupCode == groupCode)
        //                        .ToArray()
        //                        .OrderBy(item => item.SubCode);

        //    var selectList = subCodeItems.Select(item => new SelectListItem()
        //                                                        {
        //                                                            Text = item.CodeName,
        //                                                            Value = item.SubCode,
        //                                                            Selected = (selectedValue == item.SubCode)
        //                                                        }).ToList();




        //    bool isEnglish = helper.ViewContext.Controller.CurrentLanguage() == "en-US";
        //    if (isEnglish)
        //    {

        //        selectList = subCodeItems.Select(item => new SelectListItem()
        //        {
        //            Text = string.IsNullOrEmpty(item.CodeAlias) ? item.CodeName : item.CodeAlias,
        //            Value = item.SubCode,
        //            Selected = (selectedValue == item.SubCode)
        //        }).ToList();
        //    }
        //    if (includeAll)
        //    {
        //        selectList.Insert(0, new SelectListItem()
        //                                {
        //                                    Text = isEnglish ? "All" : "전체",
        //                                    Value = string.Empty,
        //                                    Selected = true
        //                                });
        //    }
        //    return helper.RadioButtonList(name, selectList, routeValue, itemRouteValue);
        //}

        //public static string ToGroupRadioButtonList(this HtmlHelper helper, string name, string groupCode, string selectedValue, bool includeAll, object routeValue, object itemRouteValue, object labelRouteValue)
        //{
        //    var subCodeItems = EntityContext.vw_T_SC_SubCode
        //        .Where(item => item.GroupCode == groupCode)
        //        //.Where(item => item.GroupCode == groupCode)
        //                        .ToArray()
        //                        .OrderBy(item => item.SubCode);

        //    var selectList = subCodeItems.Select(item => new SelectListItem()
        //    {
        //        Text = item.CodeName,
        //        Value = item.SubCode,
        //        Selected = (selectedValue == item.SubCode)
        //    }).ToList();
        //    bool isEnglish = helper.ViewContext.Controller.CurrentLanguage() == "en-US";
        //    if (isEnglish)
        //    {

        //        selectList = subCodeItems.Select(item => new SelectListItem()
        //        {
        //            Text = string.IsNullOrEmpty(item.CodeAlias) ? item.CodeName : item.CodeAlias,
        //            Value = item.SubCode,
        //            Selected = (selectedValue == item.SubCode)
        //        }).ToList();
        //    }

        //    if (includeAll)
        //    {
        //        selectList.Insert(0, new SelectListItem()
        //        {
        //            Text = isEnglish ? "All" : "전체",
        //            Value = string.Empty,
        //            Selected = true
        //        });
        //    }
        //    return helper.RadioButtonList(name, selectList, routeValue, itemRouteValue, labelRouteValue);
        //}


        //static public MvcHtmlString ToMenuDroplist(this HtmlHelper htmlHelper, string name, int menuId, object html)
        //{
        //    var menus = EntityContext.T_SC_Menu
        //                    .Select(item => new SelectListItem
        //                    {
        //                        Selected = (item.MenuID == menuId),
        //                        Text = item.MenuName,
        //                        Value = item.MenuID.ToString(),

        //                    }).AsEnumerable();
        //    return htmlHelper.DropDownList(name, menus, html);
        //}


        ///// <summary>
        ///// language dropdown, use in UserInGroup view
        ///// </summary>
        ///// <param name="htmlHelper"></param>
        ///// <param name="name"></param>
        ///// <param name="langId"></param>
        ///// <param name="htmlAttributes"></param>
        ///// <returns></returns>
        //static public MvcHtmlString ToLanguageDropDown(this HtmlHelper htmlHelper, string name, string langId, object htmlAttributes)
        //{
        //    if (langId == null)
        //    {
        //        langId = "ko-KR";
        //    }

        //    bool isEnglish = htmlHelper.ViewContext.Controller.CurrentLanguage() == "en-US";
        //    var dropdown = new List<SelectListItem> {
        //        new SelectListItem() {
        //                Text = isEnglish ? "English" : "엉어",
        //                Value = "en-US",
        //                Selected = langId == "en-US"
        //        },
        //        new SelectListItem() {
        //                Text = isEnglish ? "Korean" : "한국어",
        //                Value = "ko-KR",
        //                Selected = langId == "ko-KR"
        //        }
        //    };

        //    return htmlHelper.DropDownList(name, dropdown, htmlAttributes);
        //}


        //static public string ToViewCommonCode(this HtmlHelper htmlHelper, string groupCode, string subCode)
        //{
        //    var code = EntityContext.vw_T_SC_SubCode
        //        .FirstOrDefault(item => item.GroupCode == groupCode && item.SubCode == subCode);
        //    return code != null ? code.CodeName : string.Empty;
        //}

        ///// <summary>
        ///// Get SelectList of SubCode
        ///// </summary>
        ///// <param name="htmlHelper"></param>
        ///// <param name="name"></param>
        ///// <param name="groupCode"></param>
        ///// <param name="includeAll"></param>
        ///// <returns></returns>
        //static public List<SelectListItem> ToSubCodeList(this HtmlHelper htmlHelper, string groupCode, bool includeAll)
        //{
        //    Controller controller = htmlHelper.ViewContext.Controller as Controller;
        //    if (controller == null)
        //    {
        //        return new List<SelectListItem>();
        //    }

        //    var subCodeItems = EntityContext.vw_T_SC_SubCode
        //        .Where(item => item.GroupCode == groupCode)
        //            .ToArray()
        //            .OrderBy(item => item.SubCode);

        //    bool isEnglish = htmlHelper.ViewContext.Controller.CurrentLanguage() == "en-US";
        //    List<SelectListItem> selectList = null;
        //    if (isEnglish)
        //    {
        //        selectList = subCodeItems.Select(item => new SelectListItem()
        //        {
        //            Text = string.IsNullOrEmpty(item.CodeAlias) ? item.CodeName : item.CodeAlias,
        //            Value = item.SubCode,
        //            Selected = false
        //        }).ToList();
        //    }
        //    else
        //    {
        //        selectList = subCodeItems.Select(item => new SelectListItem()
        //        {
        //            Text = item.CodeName,
        //            Value = item.SubCode,
        //            Selected = false
        //        }).ToList();
        //    }

        //    if (includeAll)
        //    {
        //        selectList.Insert(0, new SelectListItem()
        //        {
        //            Text = isEnglish ? "All" : "전체",
        //            Value = string.Empty,
        //            Selected = true
        //        });
        //    }

        //    return selectList;
        //}

        //static public string ToGroupDroplist(this HtmlHelper htmlHelper,
        //                                string name, string groupCode, string subCode, object htmlAttributes)
        //{
        //    return htmlHelper.ToGroupDroplist(name, groupCode, subCode, false, htmlAttributes);
        //}

        //static public string ToGroupDroplist(this HtmlHelper htmlHelper,
        //                                string name, string groupCode, string subCode)
        //{
        //    return htmlHelper.ToGroupDroplist(name, groupCode, subCode, false);
        //}

        //static public string ToGroupDroplist(this HtmlHelper htmlHelper,
        //                        string name, string groupCode, string subCode, bool includeAll)
        //{
        //    Controller controller = htmlHelper.ViewContext.Controller as Controller;
        //    if (controller != null)
        //    {
        //        return htmlHelper.ToGroupDroplist(name, groupCode, subCode, includeAll);
        //    }
        //    return string.Empty;
        //}

        //static public MvcHtmlString ToTrueFalseDropDown(this HtmlHelper htmlHelper,
        //    string name, object value, string trueLabel, string falseLabel, bool includeAll)
        //{
        //    return ToTrueFalseDropDown(htmlHelper, name, value, trueLabel, falseLabel, includeAll, null);
        //}

        //static public MvcHtmlString ToTrueFalseDropDown(this HtmlHelper htmlHelper,
        //    string name, object value, string trueLabel, string falseLabel, object htmlAttributes)
        //{
        //    return ToTrueFalseDropDown(htmlHelper, name, value, trueLabel, falseLabel, false, htmlAttributes);
        //}

        //static public MvcHtmlString ToTrueFalseDropDown(this HtmlHelper htmlHelper,
        //    string name, object value, string trueLabel, string falseLabel, bool includeAll, object htmlAttributes)
        //{
        //    string v = value == null ? string.Empty : value.ToString();

        //    var selectList = new List<SelectListItem>() {
        //        new SelectListItem() 
        //        { 
        //            Selected = v == "True",
        //            Text = trueLabel,
        //            Value = "True"
        //        }, 
        //        new SelectListItem() 
        //        {
        //            Selected = v == "False",
        //            Text = falseLabel,
        //            Value = "False"
        //        }
        //    };

        //    bool isEnglish = htmlHelper.ViewContext.Controller.CurrentLanguage() == "en-US";

        //    if (includeAll)
        //    {
        //        selectList.Insert(0, new SelectListItem()
        //        {
        //            Text = isEnglish ? "All" : "전체",
        //            Value = string.Empty,
        //            Selected = v == string.Empty
        //        });
        //    }

        //    return htmlHelper.DropDownList(name, selectList, htmlAttributes == null ? new { } : htmlAttributes);
        //}

        //static public string ToGroupDroplist(this HtmlHelper htmlHelper,
        //                        string name, string groupCode, string subCode, bool includeAll, object htmlAttributes)
        //{
        //    Controller controller = htmlHelper.ViewContext.Controller as Controller;
        //    if (controller != null)
        //    {
        //        return htmlHelper.ToGroupDroplist(name, groupCode, subCode, includeAll, htmlAttributes);
        //    }
        //    return string.Empty;
        //}


        //static public MvcHtmlString ToGroupDroplistFull(this HtmlHelper htmlHelper,
        //           string name, string groupCode, string subCode,
        //           bool includeAll, string selectText, object htmlAttributes)
        //{
        //    var subCodeItems = EntityContext.vw_T_SC_SubCode
        //        .Where(item => item.GroupCode == groupCode)
        //            .ToArray()
        //            .OrderBy(item => item.SubCode);

        //    bool isEnglish = htmlHelper.ViewContext.Controller.CurrentLanguage() == "en-US";
        //    var selectList = subCodeItems.Select(item => new SelectListItem()
        //    {
        //        Text = item.CodeName,
        //        Value = item.SubCode,
        //        Selected = (subCode == item.SubCode)
        //    }).ToList();
        //    if (isEnglish)
        //    {
        //        selectList = subCodeItems.Select(item => new SelectListItem()
        //        {
        //            Text = string.IsNullOrEmpty(item.CodeAlias) ? item.CodeName : item.CodeAlias,
        //            Value = item.GroupCode.Trim() + item.SubCode.Trim(),
        //            Selected = (subCode == item.SubCode)
        //        }).ToList();
        //    }

        //    if (includeAll)
        //    {
        //        selectList.Insert(0, new SelectListItem()
        //        {
        //            Text = selectText == string.Empty ? (isEnglish ? "All" : "전체") : selectText,
        //            Value = string.Empty,
        //            Selected = true
        //        });
        //    }

        //    return htmlHelper.DropDownList(name, selectList, htmlAttributes);
        //}

        //static public MvcHtmlString ToNumericDropdown(this HtmlHelper htmlHelper,
        //           string name, int minValue, int maxValue, int value, object htmlAttributes)
        //{
        //    List<SelectListItem> selectList = new List<SelectListItem>();
        //    for (int i = minValue; i < maxValue + 1; i++)
        //    {
        //        selectList.Add(new SelectListItem()
        //        {
        //            Text = i.ToString(),
        //            Value = i.ToString(),
        //            Selected = i == value
        //        });
        //    }
        //    return htmlHelper.DropDownList(name, selectList, htmlAttributes);
        //}


        //static public MvcHtmlString ToGroupDroplist(this HtmlHelper htmlHelper,
        //                string name, string groupCode, string subCode,
        //                Guid siteCode, bool includeAll)
        //{
        //    bool isEnglish = htmlHelper.ViewContext.Controller.CurrentLanguage() == "en-US";
        //    var subCodeItems = EntityContext.vw_T_SC_SubCode
        //        .Where(item => item.GroupCode == groupCode)
        //            .ToArray()
        //            .OrderBy(item => item.SubCode);

        //    var selectList = subCodeItems.Select(item => new SelectListItem()
        //                                                                {
        //                                                                    Text = item.CodeName,
        //                                                                    Value = item.SubCode,
        //                                                                    Selected = (subCode == item.SubCode)
        //                                                                }).ToList();
        //    if (isEnglish)
        //    {
        //        selectList = subCodeItems.Select(item => new SelectListItem()
        //        {
        //            Text = string.IsNullOrEmpty(item.CodeAlias) ? item.CodeName : item.CodeAlias,
        //            Value = item.SubCode,
        //            Selected = (subCode == item.SubCode)
        //        }).ToList();
        //    }
        //    if (includeAll)
        //    {
        //        selectList.Insert(0, new SelectListItem()
        //                                                {
        //                                                    Text = isEnglish ? "All" : "전체",
        //                                                    Value = string.Empty,
        //                                                    Selected = true
        //                                                });
        //    }

        //    return htmlHelper.DropDownList(name, selectList);
        //}


        //static public MvcHtmlString YearList(this HtmlHelper htmlHelper, string name, int from, int to, int selectedValue, object htmlAttributes)
        //{
        //    List<SelectListItem> selectList = new List<SelectListItem>();
        //    for (int i = from; i <= to; i++)
        //    {
        //        SelectListItem temp = new SelectListItem();
        //        temp.Selected = (i == selectedValue);
        //        temp.Text = i.ToString();
        //        temp.Value = i.ToString();
        //        selectList.Add(temp);
        //    }
        //    return htmlHelper.DropDownList(name, selectList, htmlAttributes);
        //}

        //static public MvcHtmlString YearList2(this HtmlHelper htmlHelper, string name, int from, int to, int selectedValue, bool includeAll, object htmlAttributes)
        //{
        //    List<SelectListItem> selectList = new List<SelectListItem>();

        //    if (includeAll)
        //    {
        //        bool isEnglish = htmlHelper.ViewContext.Controller.CurrentLanguage() == "en-US";

        //        SelectListItem all = new SelectListItem();
        //        all.Text = isEnglish ? "All" : "전체";
        //        all.Selected = selectedValue == 0;
        //        all.Value = "0";
        //        selectList.Add(all);
        //    }

        //    for (int i = from; i <= to; i++)
        //    {
        //        SelectListItem temp = new SelectListItem();
        //        temp.Selected = (i == selectedValue);
        //        temp.Text = i.ToString();
        //        temp.Value = i.ToString();
        //        selectList.Add(temp);
        //    }
        //    return htmlHelper.DropDownList(name, selectList, htmlAttributes);
        //}

        //static public MvcHtmlString MonthList(this HtmlHelper htmlHelper, string name, int selectedValue, object htmlAttributes)
        //{
        //    List<SelectListItem> selectList = new List<SelectListItem>();
        //    for (int i = 1; i <= 12; i++)
        //    {
        //        SelectListItem temp = new SelectListItem();
        //        temp.Selected = (i == selectedValue);
        //        temp.Text = i.ToString();
        //        temp.Value = i.ToString();
        //        selectList.Add(temp);
        //    }
        //    return htmlHelper.DropDownList(name, selectList, htmlAttributes);
        //}

        //static public MvcHtmlString MonthList2(this HtmlHelper htmlHelper, string name, string selectedValue, bool includeAll, object htmlAttributes)
        //{
        //    List<SelectListItem> selectList = new List<SelectListItem>();

        //    if (includeAll)
        //    {
        //        bool isEnglish = htmlHelper.ViewContext.Controller.CurrentLanguage() == "en-US";

        //        SelectListItem all = new SelectListItem();
        //        all.Text = isEnglish ? "All" : "전체";
        //        all.Selected = selectedValue == "0";
        //        all.Value = "0";
        //        selectList.Add(all);
        //    }

        //    for (int i = 1; i <= 12; i++)
        //    {
        //        SelectListItem temp = new SelectListItem();
        //        temp.Selected = (i.ToString("d2") == selectedValue);
        //        temp.Text = i.ToString("d2");
        //        temp.Value = i.ToString("d2");
        //        selectList.Add(temp);
        //    }

        //    return htmlHelper.DropDownList(name, selectList, htmlAttributes);
        //}


        ///// <summary>
        ///// Show Htmlhelp time picker..
        ///// </summary>
        ///// <param name="htmlHelper"></param>
        ///// <param name="name"></param>
        ///// <param name="selectedValue"></param>
        ///// <param name="htmlAttributes"></param>
        ///// <returns></returns>
        //static public MvcHtmlString TimePicker(this HtmlHelper htmlHelper, string name, string selectedValue, object htmlAttributes)
        //{
        //    List<SelectListItem> selectList = new List<SelectListItem>();
        //    for (int i = 0; i < 24; i++)
        //    {
        //        string time = i.ToString("00") + ":00";
        //        SelectListItem temp = new SelectListItem();
        //        temp.Text = time;
        //        temp.Value = time;
        //        temp.Selected = (selectedValue == time);
        //        selectList.Add(temp);

        //        time = i.ToString("00") + ":15";
        //        temp = new SelectListItem();
        //        temp.Text = time;
        //        temp.Value = time;
        //        temp.Selected = (selectedValue == time);
        //        selectList.Add(temp);

        //        time = i.ToString("00") + ":30";
        //        temp = new SelectListItem();
        //        temp.Text = time;
        //        temp.Value = time;
        //        temp.Selected = (selectedValue == time);
        //        selectList.Add(temp);

        //        time = i.ToString("00") + ":45";
        //        temp = new SelectListItem();
        //        temp.Text = time;
        //        temp.Value = time;
        //        temp.Selected = (selectedValue == time);
        //        selectList.Add(temp);
        //    }
        //    return htmlHelper.DropDownList(name, selectList, htmlAttributes);
        //}

        //#region Render Page Title

        //static public MvcHtmlString RenderPageTitle(this HtmlHelper htmlHelper, string pageIconUrl, string controllerName)
        //{
        //    return RenderPageTitle(htmlHelper, pageIconUrl, controllerName, string.Empty);
        //}

        //static public MvcHtmlString RenderPageTitle(this HtmlHelper htmlHelper, string pageIconUrl, string controllerName, string actionName)
        //{
        //    controllerName = controllerName.ToLower();
        //    string action = string.IsNullOrEmpty(actionName) ? htmlHelper.ActionName().ToLower() : actionName.ToLower();

        //    // get current menu            
        //    T_SC_Menu menu = null;

        //    if (controllerName == "ib")
        //    {
        //        var routes = htmlHelper.ViewContext.RouteData.Values;
        //        if (routes.ContainsKey("id"))
        //        {
        //            action = routes["id"].ToString();
        //        }
        //        else
        //        {
        //            if (action == "boarddetail" || action == "boardaddnew")
        //            {
        //                action = htmlHelper.ViewContext.HttpContext.Session["BoardId"] == null ? "0" : htmlHelper.ViewContext.HttpContext.Session["BoardId"].ToString();
        //            }

        //            if (action == "0")
        //            {
        //                int boardDocId = 0;
        //                string bid = htmlHelper.ViewContext.HttpContext.Request.Params["boardDocId"];
        //                int.TryParse(bid, out boardDocId);

        //                // Get board info
        //                var returnValues = EntityContext.ExecuteStoreQuery<int?>("SELECT TOP 1 BoardId FROM dbo.T_GW_BoardContent WHERE BoardDocId = {0}",  boardDocId).ToArray();

        //                if (returnValues != null && returnValues.Length > 0)
        //                {
        //                    action = returnValues[0].Value.ToString();
        //                }
        //            }
        //        }
        //    }
        //    menu = EntityContext.T_SC_Menu.Where(o => o.Controller.ToLower() == controllerName && o.Action.ToLower().StartsWith(action)).FirstOrDefault();

        //    if (menu == null)
        //        return MvcHtmlString.Create(string.Empty);

        //    string host = string.Empty;
        //    try
        //    {
        //        host = "http://" + htmlHelper.ViewContext.HttpContext.Request.Url.Authority;
        //    }
        //    catch { }

        //    bool isEnglish = htmlHelper.ViewContext.Controller.CurrentLanguage() == "en-US";

        //    var list = EntityContext.T_SC_Menu.Where(o => o.Controller != null);
        //    controllerName = controllerName.ToLower();

        //    T_SC_Menu menu2 = new T_SC_Menu();
        //    if (!(menu.UseYN ?? false))
        //    {
        //        menu2 = EntityContext.T_SC_Menu.FirstOrDefault(p => p.MenuID == menu.UpMenuID);
        //    }
        //    else
        //    {
        //        menu2 = menu;
        //    }

        //    List<T_SC_Menu> upMenuList = new List<T_SC_Menu>();
        //    T_SC_Menu upMenu = EntityContext.T_SC_Menu.FirstOrDefault(p => p.MenuID == menu2.UpMenuID);
        //    if (upMenu == null)
        //    {
        //        upMenu = menu2;
        //    }
        //    while (upMenu != null)
        //    {
        //        upMenuList.Add(upMenu);
        //        upMenu = EntityContext.T_SC_Menu.FirstOrDefault(p => p.MenuID == upMenu.UpMenuID);
        //    }

        //    string navigation = string.Empty;
        //    foreach (var item in upMenuList)
        //    {
        //        string href = string.IsNullOrEmpty(item.Controller) ? "#" : "/" + item.Controller + "/" + item.Action;
        //        navigation = string.Format("&nbsp;&gt;&nbsp;<a href=\"{1}\">{0}</a>", isEnglish ? item.MenuNameEn : item.MenuName, href) + navigation;
        //    }

        //    /*
        //    // add home
        //    // get list of top menu excepts System Menu if admin, check admin site
        //    var isAdmin = PersonalUtility.IsAdminUser(htmlHelper.ViewContext.HttpContext.User.Identity.Name);

        //    string fullUrl = htmlHelper.ViewContext.HttpContext.Request.Url.ToString();
        //    isAdmin &= evEIS.Repository.PersonalUtility.IsAdminSite(fullUrl);
        //    */
        //    // logo click, home url
        //    string homeUrl = "/Home";//evEIS.Repository.PersonalUtility.GetHomeUrl(fullUrl);
        //    navigation = string.Format("<a href=\"{0}\">Home</a>", homeUrl) + navigation;

        //    // itself
        //    string title = isEnglish ? menu.MenuNameEn : menu.MenuName;
        //    navigation += string.Format("&nbsp;&gt;&nbsp;<strong>{0}</strong>", title);

            
        //   return RenderPageTitle2(htmlHelper, pageIconUrl, title, navigation);
        //}

        //static public MvcHtmlString RenderPageTitle2(this HtmlHelper htmlHelper, string pageIconUrl, string pageTitle, string navigation)
        //{
        //    StringBuilder sb = new StringBuilder();
        //    //sb.Append("<div>");
        //    //sb.AppendFormat("<img src=\"{0}\" align=\"absmiddle\"/>&nbsp;{1}", pageIconUrl, pageTitle);
        //    //sb.AppendFormat("<span>{0}</span> </div>", navigation);

        //    sb.Append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"width:100%;\">");
        //    sb.AppendFormat("<tr><td align=\"left\" valign=\"top\" style=\"font-weight:bold; font-size: 10pt;width: 40%;\"><img src=\"{0}\" align=\"absmiddle\"/>&nbsp;{1}</td>", pageIconUrl, pageTitle);
        //    sb.AppendFormat("<td align=\"right\" valign=\"top\">{0}</td></tr></table>", navigation);

        //    return MvcHtmlString.Create(sb.ToString());
        //}

        //static public MvcHtmlString RenderPageTitlePop(this HtmlHelper htmlHelper, string pageIconUrl, string pageTitle, string navigation)
        //{
        //    StringBuilder sb = new StringBuilder();
        //    //sb.Append("<div>");
        //    //sb.AppendFormat("<img src=\"{0}\" align=\"absmiddle\"/>&nbsp;{1}", pageIconUrl, pageTitle);
        //    //sb.AppendFormat("<span>{0}</span> </div>", navigation);

        //    sb.Append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"3\" style=\"width:100%;\">");
        //    sb.AppendFormat("<tr><td align=\"left\" valign=\"top\" style=\"font-weight:bold; font-size: 10pt;width: 95%;\"><img src=\"{0}\" align=\"absmiddle\"/>&nbsp;{1}</td>", pageIconUrl, pageTitle);
        //    sb.AppendFormat("<td align=\"right\" valign=\"top\">{0}</td></tr></table>", navigation);
        //    //sb.Append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"width:100%;\">");
        //    //sb.AppendFormat("<tr><td align=\"left\" valign=\"top\" style=\"font-weight:bold; font-size: 10pt; width: 90%;\"><img src=\"{0}\" align=\"absmiddle\"/>&nbsp;{1}</td>", pageIconUrl, pageTitle);
        //    //sb.AppendFormat("<td align=\"right\" valign=\"top\">{0}</td></tr></table>", navigation);

        //    return MvcHtmlString.Create(sb.ToString());
        //}

        //static public MvcHtmlString RenderPageTitlePop(this HtmlHelper htmlHelper, string pageIconUrl, string pageTitle)
        //{
        //    StringBuilder sb = new StringBuilder();
        //    //sb.Append("<div>");
        //    //sb.AppendFormat("<img src=\"{0}\" align=\"absmiddle\"/>&nbsp;{1}", pageIconUrl, pageTitle);
        //    //sb.AppendFormat("<span>{0}</span> </div>", navigation);

        //    sb.Append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"3\" style=\"width:100%;\">");
        //    sb.AppendFormat("<tr><td align=\"left\" valign=\"top\" style=\"font-weight:bold; font-size: 10pt;width: 95%;\"><img src=\"{0}\" align=\"absmiddle\"/>&nbsp;{1}</td>", pageIconUrl, pageTitle);
        //    sb.AppendFormat("<td align=\"right\" valign=\"top\"></td></tr></table>");
        //    //sb.Append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"width:100%;\">");
        //    //sb.AppendFormat("<tr><td align=\"left\" valign=\"top\" style=\"font-weight:bold; font-size: 10pt; width: 90%;\"><img src=\"{0}\" align=\"absmiddle\"/>&nbsp;{1}</td>", pageIconUrl, pageTitle);
        //    //sb.AppendFormat("<td align=\"right\" valign=\"top\">{0}</td></tr></table>", navigation);

        //    return MvcHtmlString.Create(sb.ToString());
        //}

        //#endregion

        //#region Render Page Title Mail List

        //static public MvcHtmlString RenderPageTitleMailList(this HtmlHelper htmlHelper, string pageIconUrl, string controllerName, string folderPath, string folderName)
        //{
        //    return RenderPageTitleMailList(htmlHelper, pageIconUrl, controllerName, string.Empty, folderPath, folderName);
        //}

        //static public MvcHtmlString RenderPageTitleMailList(this HtmlHelper htmlHelper, string pageIconUrl, string controllerName, string actionName, string folderPath, string folderName)
        //{
        //    controllerName = controllerName.ToLower();
        //    string action = string.IsNullOrEmpty(actionName) ? htmlHelper.ActionName().ToLower() : actionName.ToLower();

        //    // get current menu            
        //    var menu = EntityContext.T_SC_Menu.Where(o => o.Controller.ToLower() == controllerName && o.Action.ToLower().StartsWith(action)).FirstOrDefault();

        //    if (menu == null)
        //        return MvcHtmlString.Create(string.Empty);

        //    string host = string.Empty;
        //    try
        //    {
        //        host = "http://" + htmlHelper.ViewContext.HttpContext.Request.Url.Authority;
        //    }
        //    catch { }

        //    bool isEnglish = htmlHelper.ViewContext.Controller.CurrentLanguage() == "en-US";

        //    var list = EntityContext.T_SC_Menu.Where(o => o.Controller != null);
        //    controllerName = controllerName.ToLower();

        //    if (!(menu.UseYN ?? false))
        //    {
        //        menu = EntityContext.T_SC_Menu.FirstOrDefault(p => p.MenuID == menu.UpMenuID);
        //    }

        //    List<T_SC_Menu> upMenuList = new List<T_SC_Menu>();
        //    upMenuList.Add(menu);
        //    T_SC_Menu upMenu = EntityContext.T_SC_Menu.FirstOrDefault(p => p.MenuID == menu.UpMenuID);
        //    while (upMenu != null)
        //    {
        //        upMenuList.Add(upMenu);
        //        upMenu = EntityContext.T_SC_Menu.FirstOrDefault(p => p.MenuID == upMenu.UpMenuID);
        //    }

        //    string navigation = string.Empty;
        //    foreach (var item in upMenuList)
        //    {
        //        string href = string.IsNullOrEmpty(item.Controller) ? "#" : "/" + item.Controller + "/" + item.Action;
        //        navigation = string.Format("&nbsp;&gt;&nbsp;<a href=\"{1}\">{0}</a>", isEnglish ? item.MenuNameEn : item.MenuName, href) + navigation;
        //    }

        //    /*
        //    // add home
        //    // get list of top menu excepts System Menu if admin, check admin site
        //    var isAdmin = PersonalUtility.IsAdminUser(htmlHelper.ViewContext.HttpContext.User.Identity.Name);

        //    string fullUrl = htmlHelper.ViewContext.HttpContext.Request.Url.ToString();
        //    isAdmin &= evEIS.Repository.PersonalUtility.IsAdminSite(fullUrl);
        //    */
        //    // logo click, home url
        //    string homeUrl = "/Home";//evEIS.Repository.PersonalUtility.GetHomeUrl(fullUrl);
        //    navigation = string.Format("<a href=\"{0}\">Home</a>", homeUrl) + navigation;

        //    // itself
        //    string title = isEnglish ? menu.MenuNameEn : menu.MenuName;
        //    //navigation += string.Format("&nbsp;&gt;&nbsp;{0}", title);

        //    return RenderPageTitle2MailList(htmlHelper, pageIconUrl, title, navigation, folderPath, folderName);
        //}

        //static public MvcHtmlString RenderPageTitle2MailList(this HtmlHelper htmlHelper, string pageIconUrl, string pageTitle, string navigation, string folderPath, string folderName)
        //{
        //    StringBuilder sb = new StringBuilder();
        //    sb.Append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"width:100%;\">");
        //    sb.AppendFormat("<tr><td align=\"left\" valign=\"top\" style=\"font-weight:bold; font-size: 10pt; width: 50%;\"><img src=\"{0}\" align=\"absmiddle\"/><span id=\"spanTextTitle\">&nbsp;{1}</span></td>", pageIconUrl, folderName);
        //    sb.AppendFormat("<td align=\"right\" valign=\"top\">{0}&nbsp;&gt;&nbsp;{1}</td></tr></table>", navigation, folderPath);

        //    return MvcHtmlString.Create(sb.ToString());
        //}

        //#endregion


        //#region File Upload Control

        ////static public string RenderFileList(this HtmlHelper htmlHelper, string name, int? fileGroupId, object properties, object htmlAttributes)
        ////{
        ////    string result = htmlHelper.Hidden(name, fileGroupId != null ? fileGroupId.Value.ToString() : "0").ToHtmlString();
        ////    RouteValueDictionary routeAttributes = new RouteValueDictionary(htmlAttributes);
        ////    RouteValueDictionary routeProperties = new RouteValueDictionary(properties);
        ////    TagBuilder tagBuilder = new TagBuilder("div");
        ////    tagBuilder.Attributes.Add("id", "fileListContent" + name);
        ////    tagBuilder.MergeAttributes(routeAttributes, true);
        ////    result += tagBuilder.ToString();

        ////    string script = string.Empty;
        ////    foreach (var item in routeProperties)
        ////    {
        ////        script += "SC_FileUtility." + item.Key + "=";
        ////        script += item.Value.ToString().ToLower() + ";";
        ////    }

        ////    result += "<script type=\"text/javascript\">LoadHelper.registerLoad(function(){" + script + "; SC_FileUtility.loadIndexForm('" + name + "')});</script>";

        ////    return result;
        ////}

        ///// <summary>
        ///// Render file view only
        ///// </summary>
        ///// <param name="htmlHelper"></param>
        ///// <param name="name"></param>
        ///// <param name="fileGroupId"></param>
        ///// <returns></returns>
        //static public string RenderFileView(this HtmlHelper htmlHelper, string name, int? fileGroupId)
        //{
        //    // get file list
        //    FileUtility file = new FileUtility();
        //    var list = file.GetFileListView(fileGroupId ?? 0);
        //    foreach (var item in list)
        //    {
        //        item.FileLink = string.Format("<a href=\"{0}FileUpload/DownloadFiles?itemIds={1}\">{2}</a>",
        //            htmlHelper.ViewContext.HttpContext.Request.ApplicationPath, item.FileId, item.Name);
        //    }

        //    ViewDataDictionary vd = new ViewDataDictionary(list);
        //    vd.Add("NameGrid", name);
        //    ViewPage vp = new ViewPage { ViewData = vd, ViewContext = htmlHelper.ViewContext };
        //    Control control = vp.LoadControl("~/Views/FileUpload/FileListView.ascx");
        //    vp.Controls.Add(control);

        //    StringBuilder sb = new StringBuilder();
        //    using (StringWriter sw = new StringWriter(sb))
        //    {
        //        using (HtmlTextWriter tw = new HtmlTextWriter(sw))
        //        {
        //            vp.RenderControl(tw);
        //        }
        //    }

        //    return sb.ToString();
        //}

        //static public string RenderAttachFileList(this HtmlHelper htmlHelper, string name, string toFolder, string folderName, object properties, object htmlAttributes)
        //{
        //    string result = htmlHelper.Hidden(name, folderName).ToHtmlString();
        //    RouteValueDictionary routeAttributes = new RouteValueDictionary(htmlAttributes);
        //    RouteValueDictionary routeProperties = new RouteValueDictionary(properties);
        //    TagBuilder tagBuilder = new TagBuilder("div");
        //    tagBuilder.Attributes.Add("id", "fileListContent" + name);
        //    tagBuilder.MergeAttributes(routeAttributes, true);
        //    result += tagBuilder.ToString();

        //    string script = string.Empty;
        //    foreach (var item in routeProperties)
        //    {
        //        script += "EM_AttachFile." + item.Key + "=";
        //        script += item.Value.ToString().ToLower() + ";";
        //    }

        //    result += "<script type=\"text/javascript\">LoadHelper.registerLoad(function(){" + script + "; EM_AttachFile.loadIndexForm('" + toFolder + "','" + name + "')});</script>";

        //    return result;
        //}

        //#endregion


    }
}
